﻿using System;
using Microsoft.SharePoint.UserCode;
using Microsoft.Office.Server.Diagnostics;
using SharePointLoggerArgs;

namespace SharePointLoggerOps
{
    public class TraceProxyOps : SPProxyOperation
    {
        public override object Execute(SPProxyOperationArgs args)
        {

            TraceProxyArgs proxyArgs = null;

            if (args != null)
            {
                try
                {
                    proxyArgs = args as TraceProxyArgs;

                    PortalLog.LogString(
                        "Sandbox Logger: {0};{1};{2};{3};{4}",
                        proxyArgs.DisplayName,
                        proxyArgs.MessageType.ToString(),
                        proxyArgs.Message,
                        proxyArgs.AssemblyName,
                        proxyArgs.CorrelationID
                        );

                    return "Success: " + proxyArgs.CorrelationID.ToString(); ;
                }
                catch (Exception x)
                {
                    return "Failed " + x.Message;
                }
            }
            else
                return "Nothing to log";
        }

    }
}

